Socket
Socket
Sign inDemoInstall

rx

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rx

Library for composing asynchronous and event-based operations in JavaScript


Version published
Weekly downloads
1.5M
decreased by-0.43%
Maintainers
2
Weekly downloads
 
Created

What is rx?

The 'rx' npm package is a library for composing asynchronous and event-based programs using observable sequences. It provides powerful utilities for creating, transforming, and querying data streams.

What are rx's main functionalities?

Creating Observables

This code demonstrates how to create an Observable that emits a single value, 'Hello', and then completes.

const { Observable } = require('rx');
const observable = Observable.create(observer => {
  observer.onNext('Hello');
  observer.onCompleted();
});
observable.subscribe(value => console.log(value));

Transforming Data

This code shows how to transform data in an Observable sequence using the 'map' operator, multiplying each number by 10.

const { Observable } = require('rx');
const source = Observable.from([1, 2, 3]);
const multiplied = source.map(value => value * 10);
multiplied.subscribe(value => console.log(value));

Combining Observables

This code snippet illustrates how to combine two Observables into one using 'combineLatest', which emits values from both Observables as an array.

const { Observable } = require('rx');
const obs1 = Observable.of('Hello');
const obs2 = Observable.of('World');
const combined = Observable.combineLatest(obs1, obs2, (v1, v2) => v1 + ' ' + v2);
combined.subscribe(value => console.log(value));

Error Handling

This example demonstrates how to handle errors in an Observable sequence using the 'throw' operator and the error handling function in 'subscribe'.

const { Observable } = require('rx');
const source = Observable.throw(new Error('Oops!'));
source.subscribe(
  value => console.log(value),
  error => console.error(error.message)
);

Filtering Data

This code sample shows how to filter data in an Observable sequence using the 'filter' operator, emitting only even numbers.

const { Observable } = require('rx');
const source = Observable.from([1, 2, 3, 4, 5]);
const filtered = source.filter(value => value % 2 === 0);
filtered.subscribe(value => console.log(value));

Other packages similar to rx

Keywords

FAQs

Package last updated on 01 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc